import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';

part 'RestResult.g.dart';

@JsonSerializable()
class RestResult {
  @JsonKey(name: 'code')
  late int _code;
  @JsonKey(name: 'msg')
  late String _msg;
  @JsonKey(name: 'data')
  late Map<String, dynamic> _data;

  RestResult({int? code, String? msg, Map<String, dynamic>? data})
      : _code = code ?? 0,
        _msg = msg ?? '',
        _data = data ?? <String, dynamic>{};

  Map<String, dynamic> get data => _data;

  String get msg => _msg;

  int get code => _code;

  set code(int value) {
    _code = value;
  }

  set msg(String value) {
    _msg = value;
  }

  set data(Map<String, dynamic> value) {
    _data = value;
  }

  RestResult.fromJson(Map<String, dynamic> json)
      : _code = json['code'],
        _msg = json['msg'],
        _data = json['data'];

  Map<String, dynamic> toJson() => _$RestResultToJson(this);
}
